package org.gwt.project.tools.quickfix;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.gwt.project.tools.ToolsPlugin;

public class Generator { 
	
	public static final String PROJECT = "project";
	
	public static final String CONTAINER = "container";
	
	public static final String PROBLEM_MARKER = ToolsPlugin.ID + ".problem";
	
	public static final String PROBLEM_ID = PROBLEM_MARKER + ".id";
		
	public static IMarker createProblemMarker(
			IResource resource, 
			String problemId,
			String message,
			int priority,
			int severity,
			String location) throws CoreException {
		
		return createMarker(
				resource, 
				PROBLEM_MARKER, 
				PROBLEM_ID,
				problemId, 
				message, 
				priority, 
				severity, 
				location);
		
	}

	public static IMarker createMarker(
			IResource resource, 
			String type,
			String attId,
			String valId,
			String message,
			int priority,
			int severity,
			String location) throws CoreException {
		
		// Delete existing markers
		resource.deleteMarkers(type, true, IResource.DEPTH_INFINITE);
		
		// Create problem
		IMarker marker = resource.createMarker(type);
		
		// Set marker id (identifies marker resolution generator)
		marker.setAttribute(attId, valId);
		
		// Set attributes
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute(IMarker.PRIORITY, priority);
		marker.setAttribute(IMarker.SEVERITY, severity);
		marker.setAttribute(IMarker.LOCATION, location);
		
		// Finished
		return marker;
	}

}